      *> File Name     000019_IComparable.cbl.
      *> Description   Implementing the IComparable interface.
      *> Project Type  Console Application.
      *> CodePlex URL  http://cobol.codeplex.com
 
       program-id.   Main.
       repository.
           class animal      as "Animal"
           class sys-console as "System.Console"
           .
       working-storage section.
       01  a  animal occurs any.
       procedure division.
           move "Implementing IComparable" to sys-console::"Title"
 
           set content of a to (               
               animal::"New"("Fido")
               animal::"New"("Fido") *> two Fidos
               animal::"New"("Fifi") *> and a Fifi
           )
 
           display a(1) " vs " a(3) ": " a(1)::"CompareTo"(a(3))
           display a(1) " vs " a(2) ": " a(1)::"CompareTo"(a(2))
           display a(3) " vs " a(1) ": " a(3)::"CompareTo"(a(1))
 
           display "Press any key to continue . . . " no advancing
           invoke sys-console::"ReadKey"(true)
           .
       end program   Main.
 
       class-id.     Animal implements type "System.IComparable".
       repository.
           class    arg-exception as "System.ArgumentException"
           class    sys-type      as "System.Type"
           .
       working-storage section.
       01  _moniker  string. 
      *>
       method-id.    New.
       procedure division using by value moniker as string.
           move moniker to _moniker
           .
       end method    New.
      *>
       method-id.    get property Moniker.
       procedure division giving s as string.
           move _moniker to s.
       end method.
      *>
       method-id.    CompareTo.
       local-storage section.
       01  ex  arg-exception.
       01  t   sys-type.
       linkage section.
       01  o-rhs  object.
       01  n      binary-long.
       procedure division using by value o-rhs giving n.
           move type of animal to t
           if o-rhs::"GetType" = t then
               set n to _moniker::"CompareTo"(
                   o-rhs as animal::"Moniker")
           else
               move arg-exception::"New"(
                   "object is not of type " t::"ToString") to ex
               raise ex
           end-if
           .            
       end method    CompareTo.       
      *>
       method-id.    ToString override.
       procedure division giving s as string.
           move _moniker to s
           .
       end method    ToString.
      *>
       end class     Animal.